package com.sc.smartcommunity.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.sc.smartcommunity.common.Result;
import com.sc.smartcommunity.domain.Moment;
import com.sc.smartcommunity.domain.MomentComment;
import com.sc.smartcommunity.service.MomentService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Chenke Zhao
 * @date 2025/9/15 16:15
 * @description 朋友圈管理
 */
@RestController
@RequestMapping("/moment")
public class MomentController {

    @Resource
    private MomentService momentService;

    @Operation(summary = "发布动态")
    @PostMapping("/publish")
    @SaCheckLogin
    public Result<String> publish(@RequestBody Moment moment) {
        momentService.save(moment);
        return Result.success("发布成功");
    }

    @Operation(summary = "删除动态")
    @DeleteMapping("/delete")
    @SaCheckLogin
    public Result<String> delete(@RequestBody Moment moment) {
        momentService.removeById(moment.getId());
        return Result.success("删除成功");
    }

    @Operation(summary = "查询动态列表")
    @GetMapping("/queryList")
    @SaCheckLogin
    public Result<List<Moment>> queryList() {
        List<Moment> momentList = momentService.list();
        return Result.success(momentList);
    }

    @Operation(summary = "点赞")
    @PutMapping("/like")
    @SaCheckLogin
    public Result<String> like(@RequestBody Moment moment) {
        momentService.like(moment.getId());
        return Result.success("点赞成功");
    }

    @Operation(summary = "取消点赞")
    @PutMapping("/unlike")
    @SaCheckLogin
    public Result<String> unlike(@RequestBody Moment moment) {
        momentService.unlike(moment.getId());
        return Result.success("取消点赞成功");
    }

    @Operation(summary = "评论")
    @PutMapping("/comment")
    @SaCheckLogin
    public Result<String> comment(@RequestBody MomentComment momentComment) {
        momentService.comment(momentComment);
        return Result.success("评论成功");
    }

    @Operation(summary = "删除评论")
    @DeleteMapping("/deleteComment")
    @SaCheckLogin
    public Result<String> deleteComment(@RequestBody MomentComment momentComment) {
        momentService.deleteComment(momentComment.getId());
        return Result.success("删除评论成功");
    }

    @Operation(summary = "查询评论列表")
    @GetMapping("/queryCommentList")
    @SaCheckLogin
    public Result<List<MomentComment>> queryCommentList(@RequestParam Integer momentId) {
        List<MomentComment> momentCommentList = momentService.queryCommentList(momentId);
        return Result.success(momentCommentList);
    }

}
